﻿
@{
    ViewBag.Title = "修改广告";
}
@model KTD.Web.Models.VD.AdvCUD

<div class="x-body" id="saveResult" style="width:100%;">
    <div class="layui-form">
        @Html.HiddenFor(model => model.Id)
        @Html.HiddenFor(model => model.type)
        <div class="layui-form-item">
            <div class="layui-inline">
                <label for="L_email" class="layui-form-label">
                    <span class="x-red">*</span>标题
                </label>
                <div class="layui-input-inline">
                    @Html.TextBoxFor(model => model.advname, new { @class = "layui-input", @readOnly = true })
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_email" class="layui-form-label">
                <span class="x-red">*</span>展示图片
            </label>
            <div class="layui-input-inline">
                <input type="file" id="file" class="layui-input" />
            </div>

        </div>
        <label for="L_email" class="layui-form-label">
            <span class="x-red">*</span>内容
        </label>
        <div class="layui-form-item">


            @Html.TextAreaFor(model => model.query, new { @class = "layui-input", style = "width:100%;height:200px;display:none;" })
            <div id="editor">
                <p>
                    @Html.Raw(HttpUtility.HtmlDecode(Model.query))
                </p>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label for="L_email" class="layui-form-label">
                    <span class="x-red">*</span>是否显示
                </label>
                <div class="layui-input-inline">
                    @Html.CheckBoxFor(model => model.enabled)
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
            </label>
            <button id="btnAdd" class="layui-btn" lay-filter="add" lay-submit="">
                保存
            </button>
        </div>
    </div>
</div>



@section scripts{
    <script src="~/Scripts/wangEditor.min.js"></script>
    <script>
        $(function () {
            var E = window.wangEditor
            var editor = new E('#editor')
            // 或者 var editor = new E( document.getElementById('editor') )
            editor.create();
            $("#btnAdd").click(function () {
                $("#query").val(editor.txt.html());
                return true;
            });
        });
        layui.use(['form', 'layer'], function () {
            $ = layui.jquery;
            var form = layui.form
                , layer = layui.layer;

            //自定义验证规则
            form.verify({
                nikename: function (value) {
                    if (value.length < 5) {
                        return '昵称至少得5个字符啊';
                    }
                }
                , pass: [/(.+){6,12}$/, '密码必须6到12位']
                , repass: function (value) {
                    if ($('#L_pass').val() != $('#L_repass').val()) {
                        return '两次密码不一致';
                    }
                }
            });

            //监听提交
            form.on('submit(add)', function (data) {
                var formdata = new FormData();
                formdata.append("Id", $("#Id").val());
                formdata.append("advname", $("#advname").val());
                
                formdata.append("enabled", $("#enabled").prop('checked'));
                formdata.append("type", $("#type").val());
                formdata.append("query", $("#query").val());
                formdata.append("file", $("#file")[0].files[0]);
                $.ajax({

                    url: "/Adv/Update",
                    type: "post",
                    data: formdata,
                    processData: false,    // 不处理数据
                    contentType: false,    // 不设置内容类型

                    success: function (data) {

                        //发异步，把数据提交给php
                        layer.alert("修改成功", { icon: 6 }, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            parent.window.location.reload();
                        });
                    }
                })
                return false;
            });


        });

    </script>
}